<template>
  <div>
    <el-table v-loading="loading" :data="noticeList">
      <el-table-column label="序号" align="center" prop="order" width="50" />
      <el-table-column label="申请单" align="center" prop="noticeType" min-width="160">
        <template slot-scope="scope">
          <el-link @click="handledetailed(scope.row)" type="primary">{{ scope.row.upkeepPlanNum || '-' }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="标题" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.title || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="保养人" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          <!-- {{ scope.row.headName || '-' }} -->
          <span v-for="(v, i) in scope.row.upkeepPlanMaintainerList" :key="i">
            {{ v.maintainerName || '-' }}
            <template v-if="i !== scope.row.upkeepPlanMaintainerList.length - 1">
              ,
            </template>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="保养部门" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.deptName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="循环类型" align="center" min-width="120">
        <template slot-scope="scope">
          {{ ['循环保养', '单次保养'][scope.row.cycleType] || '-' }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="指定日期" align="center" min-width="120">
        <template slot-scope="scope">
          {{ scope.row.specifyTime || '-' }}
        </template>
      </el-table-column> -->
      <el-table-column label="生成任务" align="center" min-width="160">
        <template slot-scope="scope">
          {{ ['提前一日', '提前二日', '提前三日', '提前四日', '提前五日'][scope.row.generateTaskType] || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="验收人" align="center" min-width="120">
        <template slot-scope="scope">
          {{ scope.row.acceptorName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="验收方式" align="center" min-width="120">
        <template slot-scope="scope">
          {{ scope.row.acceptanceModeName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" min-width="120">
        <template slot-scope="scope">
          <dict-tag :options="statusAllocation" :value="scope.row.auditStatus" />
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" min-width="120">
        <template slot-scope="scope">
          <dict-tag :options="statusFlag" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="申请人" align="center" min-width="120">
        <template slot-scope="scope">
          {{ scope.row.applicantName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" min-width="150">
        <template slot-scope="scope">
          {{ scope.row.applicationTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="创建部门" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.deptName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="220" fixed="right">
        <template slot-scope="scope">
          <div align="left">
            <el-button v-hasPermi="['insurance_plan_process']" size="small" type="primary" icon="el-icon-view"
              @click="handleUpdate(scope.row)">审核流程</el-button>
            <!-- 审核状态为已通过 -->
            <el-button :disabled="!(scope.row.auditStatus === '1')" v-hasPermi="['insurance_plan_disabled']"
              v-if="scope.row.status === '0'" size="small" icon="el-icon-lock" type="danger"
              @click="handleDelete(scope.row)">禁用
            </el-button>
            <el-button :disabled="!(scope.row.auditStatus === '1')" v-hasPermi="['insurance_plan_disabled']" v-else
              size="small" type="success" icon="el-icon-unlock" @click="handleDelete(scope.row)">启用
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <div class="card-div">
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
    <!-- 审核流程 -->
    <template v-if="open">
      <Reconsideration :rowObj="rowObj"></Reconsideration>
    </template>
    <!-- 启用 -->
    <template v-if="opendetailed">
      <Detailed :rowObj="detailedObj"></Detailed>
    </template>
  </div>
</template>

<script>
import { getUpkeepPlantList, putUpdateplanChangeStatus } from "@/api/maintenance/insurance/insurance.js";
import { getuntreatedcount } from '@/api/mianBody/index.js'
export default {
  // dicts: ['sys_notice_status', 'sys_notice_type'],
  components: {
    Reconsideration: () => import('../form/reconsideration.vue'),
    Detailed: () => import('../form/detailed.vue')
  },
  data () {
    return {
      // 遮罩层
      loading: true,
      opendetailed: false,
      detailedObj: {},
      ImageOpen: false,
      ImageSrc: '',
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      dictdatalist: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层表格数据
      noticeList: [],
      rowObj: {},
      // 弹出层标题
      title: "修改设备基值",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'upkeepPlanId',
        isAsc: 'desc'//倒叙
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        noticeTitle: [
          { required: true, message: "公告标题不能为空", trigger: "blur" }
        ],
        noticeType: [
          { required: true, message: "公告类型不能为空", trigger: "change" }
        ]
      }
    };
  },
  created () {
    this.getList();
  },
  methods: {
    handleSelectImage (src) {
      this.ImageOpen = true
      this.ImageSrc = src
    },
    /** 查询列表 */
    async getList (value) {
      this.loading = true;
      let values = value || {}
      let params = {
        ...this.queryParams,
        ...values,
        // 'params[equipmentNum]': values.equipmentNum,
        // 'params[equipmentName]': values.equipmentName
      }
      getUpkeepPlantList(params).then(response => {
        this.noticeList = response.data && response.data.map((item, index) => {
          return {
            ...item,
            order: index + 1
          }
        });
        this.total = response.total;
        this.loading = false;
        getuntreatedcount().then(res => {
          this.$store.commit('SET_FEATUREMESSAGE', res.data)
        })
      });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        noticeId: undefined,
        noticeTitle: undefined,
        noticeType: undefined,
        noticeContent: undefined,
        status: "0"
      };
      this.resetForm("form");
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 打开详细弹窗
    handledetailed (row) {
      this.$parent.$parent.$parent.$parent.tabIndex = true
      this.$parent.$parent.$parent.$parent.activeName = '3'
      this.$parent.$parent.$parent.$parent.rowObj = row.upkeepPlanId
      //  this.$parent.addTab(row);
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.rowObj = row
      this.open = true
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.noticeId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 启用禁用按钮操作 */
    handleDelete (row) {
      if (row.status === '1') {//为启用
        this.opendetailed = true
        this.detailedObj = row
        return false
      }
      const noticeIds = row.title || '无名称'
      this.$confirm(`是否确认${row.status === '0' ? `禁用` : `启用`}标题为${noticeIds}的数据？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true;
        let params = {
          upkeepPlanId: row.upkeepPlanId,
          status: row.status === '0' ? 1 : 0
        }
        putUpdateplanChangeStatus(params).then(res => {
          if (res.code === 200) {
            // this.loading = false;
            this.$message.success(res.msg)
            this.getList()
          }
          this.loading = false;
        }).catch(() => { this.loading = false; });
      }).catch(() => { this.loading = false; });
    }
  },
  filters: {
  }
};
</script>
<style lang="scss" scoped>
.red {
  color: red;
}
</style>